-
Notifications
You must be signed in to change notification settings - Fork 527
Faster IFeatureCollection.Get<TFeature> #2290
Conversation
|
I broke your change? 😄 |
5b345fa
to
9c73a57
Compare
Was trying to work out how it was possible, then realized it was my new test breaking 😄 |
9c73a57
to
d5d00e3
Compare
cbd2130
to
2d17398
Compare
OSX UnitTests/netcoreapp2.0
OSX UnitTests/netcoreapp2.1 pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any idea why GetViaGeneric_First is still twice as fast as GetViaGeneric_Last? Shouldn't the JIT remove all the extra branches so it optimizes to return (ReifiedType)_specificFeature
?
} | ||
|
||
TFeature IFeatureCollection.Get<TFeature>() | ||
protected void ResetIHttpUpgradeFeature() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: missing newline
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Theoretically, isn't this exactly what Set<IHttpUpgradeFeature>(this)
should optimize to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added newline
The interfaces are object types so it produces a shared generic and doesn't branch eliminate; have raised issue https://github.com/dotnet/coreclr/issues/16266 requesting ability to mark a method and have it be generated as non-shared (though may be a large Jit change). If the method inlined (size aside), it would eliminate all the branches; but alas its an interface method and you can't inline through an interface. Additionally an explicit interface method counts as virtual method https://github.com/dotnet/coreclr/issues/16198 so will only devirtualize on a sealed type where the explicit type is known/exposed at Jit time; so this can never devirtualize and inline (currently anyway): ((IFeatureCollection)this).Set<IHttpUpgradeFeature>(this);
To work around it you could define It also seems a lot of work and hoops to jump through; as well as Jit beahviour to rely on just to avoid defining two simple Reset methods? |
Were there other changes? |
Go via Generic rather than wrapping with
(TFeature)Get(typeof(TFeature))
as it scales betterpre
post
#2012 rebased
Resolves #2303